#ifndef _MATRIX_H_
#define _MATRIX_H_

#include <math.h>
#include <memory.h>
#include <vector>
#include <algorithm>

#if !defined(fraction)
typedef long double fraction;
#endif

class AugmentedMatrix
{
public:
    AugmentedMatrix();
    ~AugmentedMatrix();

    bool setAugmentData(fraction* values, int height);
    bool setMatrixData(fraction* valves, int width, int height);

    inline fraction getResult(int y) { return augment[y]; }
    bool process();
    void print();

private:
    fraction* matrix[32];
    fraction augment[32];
    int width, height;

    void releaseData();
    bool augmentedMatrixTrans();
    bool sortLines(int p);
    void elimination(int p);
    void swap(fraction* a, fraction* b);
    void elimination_inv(int x);
    void identityMatrix();
};

#endif
